import {defineStore} from "pinia";
import type {systemType} from "./type";
import {RouteRecordRaw, useRoute} from "vue-router";

let useSystemStore = defineStore('System', {
    state: (): systemType => {
        return {
            allRoutes: [],
            a: 1,
            tabbarRoutes: [],
            cityRange:[
                {
                    name1:'市直',
                    name2:'市直部门',
                },
                {
                    name1:'蓬江',
                    name2:'蓬江',
                },
                {
                    name1:'江海',
                    name2:'高新（江海）',
                },
                {
                    name1:'新会',
                    name2:'新会',
                },
                {
                    name1:'台山',
                    name2:'台山',
                },
                {
                    name1:'开平',
                    name2:'开平',
                },
                {
                    name1:'鹤山',
                    name2:'鹤山',
                },
                {
                    name1:'恩平',
                    name2:'恩平',
                }
            ],
            cityRangeOther:[
                {
                    name1:'蓬江',
                    name2:'蓬江',
                },
                {
                    name1:'江海',
                    name2:'高新（江海）',
                },
                {
                    name1:'新会',
                    name2:'新会',
                },
                {
                    name1:'台山',
                    name2:'台山',
                },
                {
                    name1:'开平',
                    name2:'开平',
                },
                {
                    name1:'鹤山',
                    name2:'鹤山',
                },
                {
                    name1:'恩平',
                    name2:'恩平',
                },
                {
                    name1:'管辖区外',
                    name2:'管辖区外',
                },
            ],
        }
    },
    actions: {
        add(num: number) {
            this.a += num
        },
        setAllRoutes(routes: RouteRecordRaw[]) {
            this.allRoutes = routes
        },
        setTabbarRoutes(route: RouteRecordRaw) {
            let idx = this.tabbarRoutes.findIndex(item => item.path === route.path)
            if (idx === -1) {
                this.tabbarRoutes.push(route)
            }
        },
        removeTabbarRoutes(path: string) {
            let idx = this.tabbarRoutes.findIndex(item => item.path === path)
            if (idx != -1 && this.tabbarRoutes.length > 1) {
                this.tabbarRoutes.splice(idx, 1)
            }
        },

    },
    getters: {}
})

export default useSystemStore
